﻿using System;

namespace CoreLib.Extensions
{
    public static class IntExt
    {
        public static int TryParse( string value, int @default )
        {
            var parsed = -1;
            return int.TryParse( value, out parsed ) ? parsed : @default;
        }

        public static void Upto( this int target, int topInclusive, Action<int> @do )
        {
            for ( var i = target; i < topInclusive; i++ )
                @do( i );
        }

        public static void Upto( this int target, int topInclusive, Action @do )
        {
            for ( var i = target; i < topInclusive; i++ )
                @do();
        }

        public static void Times( this int target, Action @do )
        {
            for ( var i = 0; i < target; i++ )
                @do();
        }

        public static void Times( this int target, Action<int> @do )
        {
            for ( var i = 0; i < target; i++ )
                @do( i );
        }
    }
}
